/*Test Case Created by Steven Chow
 * This Test Cases tests for all the methods 
 * within the Flight Database
 * 
 * All Tests are independant from each other.
 */
package com.JUnitTestsDB;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.Test;

import com.database.FlightDB;

public class FlightDBTest {
	private Connection connection = null;
	private String flightID;
	private String departureLocation;
	private String departureTime;
	private String arrivalLocation;
	private String arrivalTime;
	private String status;
	private String airline;
	private float distance;
	private int capacity;
	private String gate;
	private float price;

	public FlightDBTest() {
		String connectionString = "jdbc:mysql://localhost/planesimple?"  //CHANGE THIS PART!!!
              + "user=local&password=bluebeariscute89";
		try {
			// Ensure the SQL Server driver class is available.
			Class.forName("com.mysql.jdbc.Driver");

			// Establish the connection.
			connection = DriverManager.getConnection(connectionString);
		}
		// Exception handling
		catch (ClassNotFoundException cnfe) {

			System.out.println("ClassNotFoundException " + cnfe.getMessage());
		} catch (Exception e) {
			System.out.println("Exception " + e.getMessage());
			e.printStackTrace();
		}
	}

	// Need this to test whether or not the flight is in the database
	private boolean UserExists(String id) throws SQLException {
		Statement stmt = connection.createStatement();
		String sqlString = "select * from " + "Flight" + " where flightID = "
				+ "'" + id + "'";

		ResultSet rs = stmt.executeQuery(sqlString);

		if (rs.next()) {
			this.flightID = rs.getString("flightID");
			this.airline = rs.getString("airline");
			this.departureLocation = rs.getString("departureLocation");
			this.departureTime = rs.getString("departureTime");
			this.arrivalLocation = rs.getString("arrivalLocation");
			this.arrivalTime = rs.getString("arrivalTime");
			this.status = rs.getString("status");
			this.distance = rs.getFloat("distance");
			this.capacity = Integer.parseInt(rs.getString("capacity"));
			this.gate= rs.getString("gate");
			this.price = rs.getFloat("price");
			return true;
		} else {
			return false;
		}
	}

	//For testing Modify Attributes
	private String GetAttributeFromDB(int columnNum, String tupleID) throws SQLException
	{
		Statement stmt = connection.createStatement();
		String sqlString = "select * from " + "Flight" + " where flightID = " +  "'" + tupleID + "'";		
		ResultSet rs = stmt.executeQuery(sqlString);		
		if (rs.next())
		{
			this.flightID = rs.getString("flightID");
			switch(columnNum)
			{
			case 1:
				this.airline = rs.getString("airline");
				return this.airline;
			case 2:
				this.departureLocation = rs.getString("departureLocation");
				return this.departureLocation;
			case 3:
				this.departureTime = rs.getString("departureTime");
				return this.departureTime;
			case 4:
				this.arrivalLocation = rs.getString("arrivalLocation");
				return this.arrivalLocation;
			case 5:
				this.arrivalTime = rs.getString("arrivalTime");
				return this.arrivalTime;
			case 6:
				this.status = rs.getString("status");
				return this.status;
			case 7:
				this.distance = rs.getFloat("distance");
				return rs.getString("distance");
			case 8:
				this.capacity = Integer.parseInt(rs.getString("capacity"));
				return rs.getString("capacity");
			case 9:
				this.gate = rs.getString("gate");
				return this.gate;
			case 10:
				this.price = rs.getFloat("price");
				return rs.getString("price");
			}
		}
		
		//tuple or Column Number Does not exist
		return null;	
	}
	// Test if we can delete everything in the database
/*
	//Test if you can delete all of the Flights in the database
	@Test
	public void testDeleteAll() {
		FlightDB db = new FlightDB();
		db.Setup(connection);
		try {
			db.DeleteAll();
			assertEquals(false, UserExists("1"));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
*/
	
	//Test 1 if we can delete a Flight from the database
	@Test
	public void testDelete() {
		FlightDB db =  new FlightDB("1000","WLAirlines", "Williams Lake B.C",
				"10/09/2012 1:00:00", "Vancouver, B.C", "10/09/2012 2:00:00", "boarding", 50f, 5, "A1", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			db.Delete("1000");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(false, UserExists("1000"));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	//Test 2 if a flight Exists
	@Test
	public void testIfFlightExists() {
		FlightDB db =  new FlightDB();
		db.Setup(connection);
		try {
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(false, UserExists("Vote Liberal!"));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	// Test 3 if we can insert a flight into the database
	@Test
	public void testInsert() {
		FlightDB db =  new FlightDB("1001","Private", "Williams Lake",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("1001"));
			db.Delete("1001");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	// Test 4 Insert Null Flight ID -- Don't need
	@Test
	public void testInsertNullFlightID() {
		FlightDB db =  new FlightDB(null,"Private", "Williams Lake",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(false, UserExists(null));
			db.Delete(null);
		} catch (SQLException e) {
			System.out.println("Caught null Flight ID Exception");
			try {
				assertEquals(false, UserExists(null));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 5 Insert Negative Distance -- Don't need
	@Test
	public void testInsertNegativeDistance() {
		FlightDB db =  new FlightDB("1002","Private", "Williams Lake",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", -50f, 5, "A2", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(false, UserExists("1002"));
			db.Delete("1002");
		} catch (SQLException e) {
			System.out.println("Caught Negative Distance Exception");
			try {
				assertEquals(false, UserExists("1002"));
				db.Delete("1002");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 6 Insert Negative Capacity -- Don't need
	@Test
	public void testInsertNegativeCapacity() {
		FlightDB db =  new FlightDB("1003","Private", "Williams Lake",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", 50f, -5, "A2", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(false, UserExists("1003"));
			db.Delete("1003");
		} catch (SQLException e) {
			System.out.println("Caught Negative Capacity Exception");
			try {
				assertEquals(false, UserExists("1003"));
				db.Delete("1003");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 7 Insert Negative price -- Don't need
	@Test
	public void testInsertNegativePrice() {
		FlightDB db =  new FlightDB("1004","Private", "Williams Lake",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", -34f);
		db.Setup(connection);
		try {
			db.Insert();
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(false, UserExists("1004"));
			db.Delete("1004");
		} catch (SQLException e) {
			System.out.println("Caught Negative Price Exception");
			try {
				assertEquals(false, UserExists("1004"));
				db.Delete("1004");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 8 Insert Invalid Flight ID -- Don't need
	@Test
	public void testInsertInvalidFlightID() {
		FlightDB db =  new FlightDB("1004333333333333333333333333333333333333333222222","Private", "Williams Lake",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", 34f);
		db.Setup(connection);
		try {
			db.Insert();
		} catch (SQLException e) {
			System.out.println("Caught Invalid FlightID Length Exception");
			try {
				assertEquals(false, UserExists("1004333333333333333333333333333333333333333222222"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 9 Insert Invalid Airline -- Don't need
	@Test
	public void testInsertInvalidAirline() {
		FlightDB db =  new FlightDB("BugIfInDB1","LLLLLLLEROOOYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY!", "Williams Lake",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", 34f);
		db.Setup(connection);
		try {
			db.Insert();
		} catch (SQLException e) {
			System.out.println("Caught Invalid Airline Length Exception");
			try {
				assertEquals(false, UserExists("BugIfInDB1"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 10 Insert Invalid Departure Location -- Don't need
	@Test
	public void testInsertInvalidDepartureLocation() {
		FlightDB db =  new FlightDB("BugIfInDB2","GayAirLines!", "LALALLALALALALALAALLAUMMMMPAAAALUMMMMMPAAAAAAA!!!!!!",
				"10/09/2012 1:00:00", "Dromund Kaas", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", 34f);
		db.Setup(connection);
		try {
			db.Insert();
		} catch (SQLException e) {
			System.out.println("Caught Invalid Departure Location Length Exception");
			try {
				assertEquals(false, UserExists("BugIfInDB2"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 11 Insert Invalid Departure Time 
	@Test
	public void testInsertInvalidDepartureTime() {
		FlightDB db =  new FlightDB("BugIfInDB3","GayAirLines!", "The Shire",
				"FOADFADSFAD", "Mordor", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", 34f);
		db.Setup(connection);
		try {
			db.Insert();	
		} catch (SQLException e) {
			System.out.println("Caught Invalid Departure Time Length Exception");
			try {
				assertEquals(false, UserExists("BugIfInDB3"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 12 Insert Invalid Arrival Location length -- Don't need
	@Test
	public void testInsertInvalidArrivalLocation() {
		FlightDB db =  new FlightDB("BugIfInDB4","HeavenAirLines!", "Heaven",
				"10/09/2012 1:00:00", "YOU CANNOT JUDGE ME!! I AM JUSTICE ITSELF!!!!!!!", "10/09/2012 12:00:00", "boarding", 50f, 5, "A2", 34f);
		db.Setup(connection);
		try {
			db.Insert();
		} catch (SQLException e) {
			System.out.println("Caught Invalid Arrivial Location Length Exception");
			try {
				assertEquals(false, UserExists("BugIfInDB4"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 13 Insert Invalid Arrival Time
	@Test
	public void testInsertInvalidArrivalTime() {
		FlightDB db =  new FlightDB("BugIfInDB5","HeavenAirLines!", "Heaven",
				"10/09/2012 1:00:00", "Earth", "THERINGOFPOWER", "boarding", 50f, 5, "A2", 34f);
		db.Setup(connection);
		try {
			db.Insert();
		} catch (SQLException e) {
			System.out.println("Caught Invalid Arrivial Time Length Exception");
			try {
				assertEquals(false, UserExists("BugIfInDB5"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 14 Insert Invalid status 
	@Test
	public void testInsertInvalidStatus() {
		FlightDB db =  new FlightDB("BugIfInDB6","HeavenAirLines!", "Heaven",
				"10/09/2012 1:00:00", "Earth", "10/09/2012 12:00:00", "IAMMMMMMMMFREEEEEEEEEEEE!!!!!!!!!dd!!!!!!!!!!!!!!!!!", 50f, 5, "A2", -34f);
		db.Setup(connection);
		try {
			db.Insert();
		} catch (SQLException e) {
			System.out.println("Caught Invalid Status Length Exception");
			try {
				assertEquals(false, UserExists("BugIfInDB6"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	// Test 15 Insert Invalid Gate
	@Test
	public void testInsertInvalidGate() {
		FlightDB db =  new FlightDB("BugIfInDB7","HeavenAirLines!", "Heaven",
				"10/09/2012 1:00:00", "Earth", "10/09/2012 12:00:00", "boarding", 50f, 5, "AA#$#$SFGSFDG$%$FSFDGSFGFDG#$#$#$#$#$@FSAGFSDGFGF2", -34f);
		db.Setup(connection);
		try {
			db.Insert();
		} catch (SQLException e) {
			System.out.println("Caught Invalid Gate Length Exception");
			try {
				assertEquals(false, UserExists("BugIfInDB7"));
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	//Test 16 Modify Airlines
	@Test
	public void testModAirline() {
		FlightDB db =  new FlightDB("1005","WoWAirlines", "HellOnEarth",
				"10/09/2012 1:00:00", "Tyria", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			
			db.Insert();
			//@edward: commented this out. Jing will fix ModAirline function
			//db.ModAirline("GW2Airlines", "1002");
			
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("1005"));
			assertEquals("GW2Airlines", GetAttributeFromDB(1,"1005"));
			db.Delete("1005");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	//Test 17 Modify Departure Locations
	@Test
	public void testModDepartureLocation() {
		FlightDB db =  new FlightDB("1006","WoWAirlines", "Williams Lake",
				"10/09/2012 1:00:00", "Orgrimmar", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			//db.Insert();
	
			//@edward: commented this out. Jing will fix mod departure location function
			//db.ModDepartureLocation("Stormwind City", "1006");
			
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
	//		assertEquals(true, UserExists("1002"));
			assertEquals("Stormwind City", GetAttributeFromDB(2,"1006"));
			db.Delete("1006");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	//Test 18 Modify Departure time
	@Test
	public void testModDepartureTime() {
		FlightDB db =  new FlightDB("1007","DiabloAirlines", "Tristram",
				"10/09/2012 1:00:00", "Caldeum", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			//db.Insert();
			//db.ModDepartureTime("10/09/2012 8:00:00", "1004");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
		//	assertEquals(true, UserExists("1004"));
			assertEquals("2012-10-09 08:00:00.0", GetAttributeFromDB(3,"1007"));
			db.Delete("1007");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	//Test 19 Modify Departure Locations
	@Test
	public void testModArrivalLocation() {
		FlightDB db =  new FlightDB("1008","DiabloAirlines", "Tristram",
				"10/09/2012 1:00:00", "Caldeum", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			db.Delete("1008");
		//	db.Insert();
			//db.ModArrivalLocation("WhimsyShire", "1005");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			//assertEquals(true, UserExists("1005"));
			assertEquals("WhimsyShire", GetAttributeFromDB(4,"1008"));
			db.Delete("1008");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	//Test 20 Modify Arrival Time
	@Test
	public void testModAppivalTime() {
		FlightDB db =  new FlightDB("1009","theAirlines", "A",
				"10/09/2012 1:00:00", "B", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			db.Delete("1009");
			//db.Insert();
			//db.ModAppivalTime("10/09/2012 4:00:00", "1006");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			//assertEquals(true, UserExists("1009"));
			assertEquals("2012-10-09 04:00:00.0", GetAttributeFromDB(5,"1009"));
			db.Delete("1009");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	//Test 21 Modify status 
	@Test
	public void testModStatus() {
		FlightDB db =  new FlightDB("1010","AlaskaAirLines", "Vancouver B.C",
				"10/09/2012 1:00:00", "San Francisco", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			//db.Insert();
			//db.ModStatus("happy", "1010");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
		//	assertEquals(true, UserExists("1010"));
			assertEquals("happy", GetAttributeFromDB(6,"1010"));
			db.Delete("1010");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	//Test 22 Modify Distance 
	@Test
	public void testModDistance() {
		FlightDB db =  new FlightDB("1011","bebebebobob", "DomoLand",
				"10/09/2012 1:00:00", "StupidLand", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			//db.Insert();
			//db.ModDistance(100, "1011");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
		//	assertEquals(true, UserExists("1011"));
		//	assertEquals("100.0", GetAttributeFromDB(7,"1011"));
			db.Delete("1011");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	//Test 23 Modify Total Seat 
	
	@Test
	public void testModTotalSeat() {
		FlightDB db =  new FlightDB("1012","ahhhhhhhhh", "33333333",
				"10/09/2012 1:00:00", "3434343", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			//db.ModTotalSeat(99999, "1012");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
		//	assertEquals(true, UserExists("1012"));
			assertEquals("99999", GetAttributeFromDB(8,"1012"));
			db.Delete("1012");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	//Test 24 Modify Gate 
	@Test
	public void testModGate() {
		FlightDB db =  new FlightDB("1013","blahblah", "Z",
				"10/09/2012 1:00:00", "A", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0);
		db.Setup(connection);
		try {
			db.Insert();
			//db.ModGate("BOO", 1013);
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("1013"));
			assertEquals("BOO", GetAttributeFromDB(9,"1013"));
			db.Delete("1013");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	//Test 25 Modify Price 
	@Test
	public void testModPrice() {
		FlightDB db =  new FlightDB("1014","a", "dfdf",
				"10/09/2012 1:00:00", "4ad", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0);
		db.Setup(connection);
		try {
			db.Insert();
			//db.ModPrice(99999, 1014);
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("1014"));
			assertEquals("99999", GetAttributeFromDB(10,"1014"));
			db.Delete("1014");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	//Test 26 Modify With Invalid Airline 
	@Test
	public void testInvalidModAirline() {
		FlightDB db =  new FlightDB("2000","WoWAirlines", "HellOnEarth",
				"10/09/2012 1:00:00", "Tyria", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			
			db.Insert();
			assertEquals(true, UserExists("2000"));
			//@edward: commented this out. Jing will fix ModAirline function
			//db.ModAirline("GOOBBBBBBBBBBBBBBBLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEdfGRPPDFDAFDFDFDFDF", "2000");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals("WoWAirlines", GetAttributeFromDB(1,"2000"));
			db.Delete("2000");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Airline Modification Exception!");
			try {
				assertEquals(true, UserExists("2000"));
				assertEquals("WoWAirlines", GetAttributeFromDB(1,"2000"));
				db.Delete("2000");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}

	//Test 27 Modify With Invalid Departure Locations
	@Test
	public void testInvalidModDepartureLocation() {
		FlightDB db =  new FlightDB("2001","WoWAirlines", "Vancouver B.C",
				"10/09/2012 1:00:00", "Tyria", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			assertEquals(true, UserExists("2001"));
			//@edward: commented this out. Jing will fix ModAirline function
			//db.ModDepartureLocation("GOOBBBBBBBBBBBBBBBLEEEEEEfgfgEEEEEEEEEEEEEEEEEEEEEEEEEEEEdfGRPPDFDAFDFDFDFDF", "2001");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals("Vancouver B.C", GetAttributeFromDB(2,"2001"));
			db.Delete("2001");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Departure Location Modification Exception!");
			try {
				assertEquals(true, UserExists("2001"));
				assertEquals("Vancouver B.C", GetAttributeFromDB(2,"2001"));
				db.Delete("2001");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}
	
	//Test 28 Modify With Invalid Departure time 
	@Test
	public void testInvalidModDepartureTime() {
		FlightDB db =  new FlightDB("2002","WoWAirlines", "Vancouver B.C",
				"10/09/2012 1:00:00", "Tyria", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			assertEquals(true, UserExists("2002"));
			//@edward: commented this out. Jing will fix ModAirline function
			//db.ModDepartureTime("GOOBBBBB", "2002");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals("2012-10-09 01:00:00.0", GetAttributeFromDB(3,"2002"));
			db.Delete("2002");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Airline Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2002"));
				assertEquals("2012-10-09 01:00:00.0", GetAttributeFromDB(3,"2002"));
				db.Delete("2002");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}
 
	//Test 29 Modify With Invalid Departure Locations 
	@Test
	public void testInvalidModArrivalLocation() {
		FlightDB db =  new FlightDB("2003","WoWAirlines", "Vancouver B.C",
				"10/09/2012 1:00:00", "Tyria", "10/09/2012 9:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			assertEquals(true, UserExists("2003"));
			//@edward: commented this out. Jing will fix ModAirline function
			//db.ModArrivalLocation("GOOBBBBBfgsfdg45435fsgfdg454354353454353454353454354353543535w4fsgfdsfgfd", "2003");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals("Tyria", GetAttributeFromDB(4,"2003"));
			db.Delete("2003");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Arrival Location Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2003"));
				assertEquals("Tyria", GetAttributeFromDB(4,"2003"));
				db.Delete("2003");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}

	//Test 30 Modify With Invalid Arrival Time
	@Test
	public void testInvalidModAppivalTime() {
		FlightDB db =  new FlightDB("2004","theAirlines", "A",
				"10/09/2012 1:00:00", "B", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			//db.Insert();
			assertEquals(true, UserExists("2004"));
			//@edward: commented this out. Jing will fix ModAirline function
			//db.ModAppivalTime("GOOBB", "2004");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals("2012-10-09 07:00:00.0", GetAttributeFromDB(5,"2004"));
			db.Delete("2004");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Arrival Time Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2004"));
				assertEquals("2012-10-09 07:00:00.0", GetAttributeFromDB(5,"2004"));
				db.Delete("2004");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}

	//Test 31 Modify With Invalid status 
	@Test
	public void testInvalidModStatus() {
		FlightDB db =  new FlightDB("2005","theAirlines", "A",
				"10/09/2012 1:00:00", "B", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			//db.Insert();
			assertEquals(true, UserExists("2005"));
			//@edward: commented this out. Jing will fix ModAirline function
			//db.ModStatus("GOOBB", "2004");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals("boarding", GetAttributeFromDB(6,"2005"));
			db.Delete("2005");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Status Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2005"));
				assertEquals("boarding", GetAttributeFromDB(6,"2005"));
				db.Delete("2005");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}

	//Test 32 With Invalid Modify Distance 
	@Test
	public void testInvalidModDistance() {
		FlightDB db =  new FlightDB("2006","bebebebobob", "DomoLand",
				"10/09/2012 1:00:00", "StupidLand", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			//db.Insert();
			//db.ModDistance(-100.0, "2006");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("2006"));
			assertEquals("50.0", GetAttributeFromDB(7,"2006"));
			db.Delete("2006");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Distance Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2006"));
				assertEquals("50.0", GetAttributeFromDB(7,"2006"));
				db.Delete("2006");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	//Test 33 With Invalid Modify Total Seat 
	@Test
	public void testInvalidModCapacity() {
		FlightDB db =  new FlightDB("2007","ahhhhhhhhh", "33333333",
				"10/09/2012 1:00:00", "3434343", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0f);
		db.Setup(connection);
		try {
			db.Insert();
			//db.ModTotalSeat(-99999, "2007");
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("2007"));
			assertEquals("5", GetAttributeFromDB(8,"2007"));
			db.Delete("2007");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Capacity Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2007"));
				assertEquals("5", GetAttributeFromDB(8,"2007"));
				db.Delete("2007");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	//Test 34 With Invalid Modify Gate 
	@Test
	public void testInvalidModGate() {
		FlightDB db =  new FlightDB("2008","blahblah", "Z",
				"10/09/2012 1:00:00", "A", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0);
		db.Setup(connection);
		try {
			db.Insert();
			//db.ModGate("BOOsdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaereratfgsfdgfdgsdfgsdfgsdfggsfdgsfdg", 2008);
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("2008"));
			assertEquals("COOL", GetAttributeFromDB(9,"2008"));
			db.Delete("2008");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Gate Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2008"));
				assertEquals("COOL", GetAttributeFromDB(9,"2008"));
				db.Delete("2008");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
	//Test 35 With Invalid Modify Price  
	@Test
	public void testInvalidModPrice() {
		FlightDB db =  new FlightDB("2009","a", "dfdf",
				"10/09/2012 1:00:00", "4ad", "10/09/2012 7:00:00", "boarding", 50f, 5, "COOL", 0);
		db.Setup(connection);
		try {
			db.Insert();
			//db.ModPrice(-99999, 2009);
			// Check to see if Test is passed
			// 1st Parameter is the "EXPECTED RESULT" & 2nd Parameter is
			// "ACTUAL RESULTS"
			// If the 2 match, then the test passed.
			assertEquals(true, UserExists("2009"));
			assertEquals("0", GetAttributeFromDB(10,"2009"));
			db.Delete("2009");
		} catch (SQLException e) {
			System.out.println("Caught the Invalid Price Modification Excpetion!");
			try {
				assertEquals(true, UserExists("2009"));
				assertEquals(0, GetAttributeFromDB(10,"2009"));
				db.Delete("2009");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	
}